﻿<%@ Page Title="" Language="C#" MasterPageFile="~/module/Fontend.Master"
    AutoEventWireup="true" CodeBehind="HealthDetails.aspx.cs" Inherits="mamnontuoitho7.module.HealthDetails" ValidateRequest="false"  %>
<%@ Import Namespace="mamnontuoitho7.AppCode" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <script language="javascript" type="text/javascript">

        function ClientComment_Click() {

            var commentContent = trim(document.getElementById("<%= txtComment.ClientID %>").value);
            var leng = commentContent.length;
            if (leng < 10 || leng > 600) {
                alert("Cần gõ hơn 10 ký tự và không quá 600 ký tự");
                return false;
            }
        }
        function CommentUpdate(i) {
            var commentContent = trim(document.getElementById("txtNewComment"+i).value);
            var leng = commentContent.length;
            if (leng < 10 || leng > 600) {
                alert("Cần gõ hơn 10 ký tự và không quá 600 ký tự");
                return false;
            }
        }
        function trim(str) {
            return str.replace(/^\s+|\s+$/g, "");
        }
    </script>
    <form id="form1" runat="server">
        <% if (_dt.Rows.Count > 0)
           {%>
        <div class="green"> <a href="Home.aspx">Trang chủ</a> &raquo; <a href="Health.aspx">Sức khỏe</a> <%= (Session["Common_articleTypeName"] != "") ? " &raquo; " + Session["Common_articleTypeName"] : ""%> &raquo;<%=_dt.Rows[0]["Title"].ToString()%></div>
        <div class="articlescontent">
            <div class="underline">
                <h2><span class="postnews">Cập nhật ngày: <%= DateTime.Parse(_dt.Rows[0]["PostDate"].ToString()).ToString("dd/MM/yyyy  HH:mm tt")%></span> <span class="view">Lượt xem: <%=_dt.Rows[0]["ViewNumber"].ToString() %></span> <span class="comment">Bình luận: <%= _comment.TotalCommentOfOneProduct(_dt.Rows[0]["ProductID"].ToString()).GetValueOrDefault() %></span>  
                    <span class="rate">Đánh giá: 
                        <ul id="unit_ul3036" class="unit-rating" style="width:80px;">
                            <li class="current-rating" style="width: <%= _start%>px">Currently 0.00/5</li>
                            <li><a href="HealthDetails.aspx?rate=1&ArticleID=<%=_articleID %>&Comment=1&page=<%= _pageflag%>" title="1 trên 5" class="r1-unit rater" rel="nofollow">1</a></li>
                            <li><a href="HealthDetails.aspx?rate=2&ArticleID=<%=_articleID %>&Comment=1&page=<%= _pageflag%>" title="2 trên 5" class="r2-unit rater" rel="nofollow">2</a></li>
                            <li><a href="HealthDetails.aspx?rate=3&ArticleID=<%=_articleID %>&Comment=1&page=<%= _pageflag%>" title="3 trên 5" class="r3-unit rater" rel="nofollow">3</a></li>
                            <li><a href="HealthDetails.aspx?rate=4&ArticleID=<%=_articleID %>&Comment=1&page=<%= _pageflag%>" title="4 trên 5" class="r4-unit rater" rel="nofollow">4</a></li>
                            <li><a href="HealthDetails.aspx?rate=5&ArticleID=<%=_articleID %>&Comment=1&page=<%= _pageflag%>" title="5 trên 5" class="r5-unit rater" rel="nofollow">5</a></li>
                        </ul>
                     </span>
                </h2>
            </div>
            <div>
                <p><%= _dt.Rows[0]["Content"].ToString() %></p>
            </div>
        </div>
        <%}
           else { 
           %>
            <div class="commingsoon">
                bài viết đã bị xóa hoặc dữ liệu không đúng ....
            </div>
           <%
           } %>
        <div class="articlemore">
            <h1 class="h1_green">
                Bài viết liên quan:</h1>
            <%
                for (int i = 0; i < _dtLink.Rows.Count; i++)
                {
                    if (_dtLink.Rows[i]["ProductID"].ToString() != _articleID)
                    {
            %>
            <div class="articlemore-link">
                <a href="HealthDetails.aspx?ArticleID=<%= _dtLink.Rows[i]["ProductID"].ToString()%>">
                   <%= _general.CutString(_general.ReplaceSpecialCharacters(_dtLink.Rows[i]["Title"].ToString()), 120)%><span> (<%= DateTime.Parse(_dtLink.Rows[i]["PostDate"].ToString()).ToString("dd/MM/yyyy")%>)</span></a></div>
            <% }
                } %>
        </div>
        <div class="articlemore">
            <h1 class="h1_green">Bình luận bài viết:</h1>
            <div class="articlecomment">
                <asp:TextBox TextMode="MultiLine" ID="txtComment" runat="server"></asp:TextBox>
                <% if (Session["username"] != "")
                   { %>
                <asp:Button ID="btnPostComment" runat="server" CssClass="buttons" Text="Bình luận"
                    OnClick="btnPostComment_Click" OnClientClick="return ClientComment_Click()" />
                <% }
                   else
                   {%>
                <a href="#loginform" onclick="showhide('loginform');" class="buttons">Đăng nhập</a>
                <%} %>
            </div>
        </div>
    </form>
    
    <%
        int _commentAmount = _dtComment.Rows.Count; 
     %>  

      <input type="hidden" id="hihCommentAmount" value="<%= _commentAmount%>" />  <%--biến cầu nối chay js tren fontend--%>
    <%
        for (int i = 0; i < _commentAmount; i++)
        {
    %>

    <div class="commentdetail"> 
        <img src="../images/avatar/teacher_parents/<%= (_dtComment.Rows[i]["Avatar"].ToString() != "") ? _dtComment.Rows[i]["Avatar"].ToString() : "icon-avatar.png" %>" alt="Mam Non Tuổi Thơ 7" />
        <span class="arrow"><span></span></span>
       
        <div id="showcontent<%= i%>" class="blockcontent">
            <div class="content">
                <%= _general.ReplaceSpecialCharacters(_dtComment.Rows[i]["ContentComment"].ToString())%>
            </div>
            <div class="info">
                    bởi <a href="ProfileInfo.aspx?MemberID=<%=_dtComment.Rows[i]["MemberID"].ToString() %>" class="groupprofile"><%= _dtComment.Rows[i]["FullName"].ToString()%></a>
                    lúc: <%= DateTime.Parse(_dtComment.Rows[i]["CreateDate"].ToString()).ToString("dd/MM/yyyy HH:mm:ss")%>
               <% bool tempbool = _comment.checkCommentOwner(Session["username"].ToString(), _dtComment.Rows[i]["CommentID"].ToString());
                   if (tempbool)
                   { %>
                    <a href="#editcontent" onclick="hide('showcontent<%= i%>'); showhide('editcontent<%= i%>');" class="buttonlink">Sửa</a>
                  <%} %>
                  <%if (Session["role"].ToString()=="1" ||Session["role"].ToString()=="2" ||Session["role"].ToString()=="5" ||Session["role"].ToString()=="7")
                    { %>
                       <a href="HealthDetails.aspx?b=<%= _dtComment.Rows[i]["CommentID"].ToString()%>&ArticleID=<%=_articleID %>&Comment=1&page=<%= _pageflag%>"  class="buttonlink" onclick="javascript: if (confirm('Bạn muốn xóa comment này?')) { window.location.href='#' } else { return false; };">
                            Xóa
                       </a>
                  <%} %>
             </div>
        </div>
         
       <div id="editcontent<%= i%>" class="blockcontent">
       <% if (tempbool){ %>
         <form method="post" action="HealthDetails.aspx?ArticleID=<%=_articleID %>&Comment=1&page=<%= _pageflag%>" id="formUpdate">
            <div class="content">
                <textarea id="txtNewComment<%= i%>" name="txtNewComment" class="textarea"><%= _dtComment.Rows[i]["ContentComment"].ToString()%></textarea>
                <input type="hidden" id="hidCommentID" name="hidCommentID" value="<%= _dtComment.Rows[i]["CommentID"].ToString()%>" />
                <input type="hidden" id="hidStatus" name="hidStatus" value="1" />
            </div>
            <div class="info">
                bởi <a href="ProfileInfo.aspx" class="groupprofile"><%= _dtComment.Rows[i]["FullName"].ToString()%></a> 
                lúc:<%= DateTime.Parse(_dtComment.Rows[i]["CreateDate"].ToString()).ToString("dd/MM/yyyy HH:mm:ss")%>
                    <a href="#showcontent" onclick="hide('editcontent<%= i%>'); showhide('showcontent<%= i%>');" class="buttonlink">Hủy</a>
                    <button type="submit" class="buttoncomment" onclick="return CommentUpdate(<%= i%>)">Cập nhật </button>
             </div>
          </form>
            <%} %>
       </div>
    </div>
    <% }%>

    <div id="container">
        <div class="pagination">
            <%if (_currentbar > 1)
              { %>
            <a href="HealthDetails.aspx?a=-1&ArticleID=<%=_articleID %>&Comment=1" class="pagegreen"><<</a>
            <%} %>
            <%  

                for (int j = _beginPage; j <= _endPage; j++)
                {
                    if (j == _pageflag)
                    {
            
            %>
            <a href="HealthDetails.aspx?page=<%= j%>&ArticleID=<%=_articleID %>&Comment=1" class="pagegreen active"><%= j%></a>
            <% }
                    else
                    { %>
            <a href="HealthDetails.aspx?page=<%= j%>&ArticleID=<%=_articleID %>&Comment=1" class="pagegreen"><%= j%></a>
            <%  }
                } %>
            <%if (_currentbar < _totalBars)
              { %>
            <a href="HealthDetails.aspx?a=1&ArticleID=<%=_articleID %>&Comment=1" class="pagegreen">>></a>
            <%} %>
          
        </div>
    </div>
</asp:Content>
